﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;
using VIW = CPPEI.ETL.Domain.Views;
using DAT = CPPEI.ETL.Domain.Data;

namespace CPPEI.ETL.WebApi.Summary
{
    /// <summary>
    /// 获取任务的概要信息
    /// </summary>
    [CPPEI.WebApi.AuthGetAction("Summary", "GetDataServiceList", "1.0")]
    public class GetDataServiceListAction : BaseAction<GetDataServiceListParams, GetDataServiceListResult>
    {
        protected override ActionResult<GetDataServiceListResult> OnExecute(ActionContext context,
            SysParameters sysParameters,
            GetDataServiceListParams opParams)
        {
            SER.QueryService service = new SER.QueryService();
            ListResult<DAT.DtSerCountSummary> result = service.Query4DtSerCount();

            if (result.IsSuccess)
            {
                GetDataServiceListResult actResult = new GetDataServiceListResult();
                for (int index = 0; index < result.Data.Count; index++)
                {
                    GetDataServiceListResult.Item taskCount = new GetDataServiceListResult.Item();
                    taskCount.TypeId = result.Data[index].TypeId;
                    taskCount.TypeText = result.Data[index].TypeText;
                    taskCount.Count = result.Data[index].Count;
                    actResult.Items.Add(taskCount);
                }

                return new ActionResult<GetDataServiceListResult>(actResult);
            }
            else
            {
                return new ActionResult<GetDataServiceListResult>(result.IsSuccess, result.ErrorCode, result.Message, null);
            }
        }
    }

    public class GetDataServiceListParams
    {
    }

    public class GetDataServiceListResult
    {
        public List<Item> Items = new List<Item>();

        public class Item
        {
            public Guid TypeId { get; set; }
            public string TypeText { get; set; }
            public int Count { get; set; }
        }
    }
}
